package main.chapter6.async

import javax.swing.SwingUtilities
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

class UIContinuationWrapper<T>(private val continuation: Continuation<T>) : Continuation<T> {
    override val context: CoroutineContext
        get() = EmptyCoroutineContext

    override fun resumeWith(result: Result<T>) {
        SwingUtilities.invokeLater {
            continuation.resumeWith(result)
        }
    }

}